/* import { createApp } from 'vue'; */
import { ElMessage, ElMessageBox } from 'element-plus'
/* import MessageComponent from '../components/MessageComponent.vue';
import ConfirmDialogComponent from '../components/ConfirmDialog.vue'; */

const MessagePlugin = {
  install(app) {
    /*     // 自定义消息实例
        const MessageInstance = createApp(MessageComponent).mount(document.createElement('div'));
    
        document.body.appendChild(MessageInstance.$el);
    
        // 确认对话框实例
        const ConfirmDialogInstance = createApp(ConfirmDialogComponent).mount(document.createElement('div'));
        document.body.appendChild(ConfirmDialogInstance.$el);
     */
    /*     // 自定义消息方法
        app.config.globalProperties.$message = {
          success(msg) {
            MessageInstance.showMessage(msg, 'success');
          },
          error(msg) {
            MessageInstance.showMessage(msg, 'error');
          }
        }; */

    /*   // 自定义确认对话框方法
      app.config.globalProperties.$baseConfirm = {
        open(options) {
          ConfirmDialogInstance.open(options);
        }
      }; */
    app.config.globalProperties.$baseConfirm = function (title, message, cb) {
      ElMessageBox.confirm(
        message,
        title,
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }
      )
        .then(() => {
          cb.call();
          ElMessage({
            type: 'success',
            message: '操作成功',
          })
        })
        .catch(() => {
          ElMessage({
            type: 'info',
            message: '操作取消',
          })
        })
    }
  }
};

export default MessagePlugin;
